package org.itboys.mobile.service.mongo.mobile;

import org.itboys.commons.utils.tools.LongUtil;
import org.itboys.mobile.common.SundayCommonConstants;
import org.itboys.mobile.dao.TianJieWalletMapper;
import org.itboys.mobile.dto.SundayCountDto;
import org.itboys.mobile.entity.mysql.TianJieWallet;
import org.itboys.mobile.service.mysql.mobile.TianJieMobileWalletService;
import org.itboys.mobile.service.mysql.web.TianJieWalletService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 作者：jiangxiong
 * 日期：2017年5月8日
 * 联系方式 ：empty90911@126.com
 * 描述：圣代_结算（确认订单）_service
 */
@Service
public class SundayMobileCountService {
    @Autowired
    private SundayMobileCartService cartService;
    @Autowired
    private TianJieMobileWalletService walletService;

 

    /**
     * 购物车结算。
     * @param memberId
     * @param cartIds
     * @param cartType
     * @return
     */
    public SundayCountDto countCart(Long memberId, List<Long> cartIds, Integer cartType){
        SundayCountDto countDto = cartService.getCart(memberId,cartIds,cartType);
        //下单用户的余额
        TianJieWallet wallet=walletService.findByMemberId(memberId);
        //用户余额
        countDto.setBalance(wallet.getUnreleaseAmount());
        return countDto;
    }


    /**
     * 立即购买结算
     * @param memberId
     * @param productId
     * @return
     */
    public SundayCountDto countBuyNow(Long memberId,Long productId,Integer num){
        List<Long> cartIds= cartService.addCart(memberId,productId ,num, SundayCommonConstants.cart_type_buy_now);
        return countCart(memberId,cartIds,SundayCommonConstants.cart_type_buy_now);
    }


}
